﻿using Common;
using ConsulEx.Model.Res;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsulEx
{
    /// <summary>
    /// 针对服务的帮助类
    /// </summary>
    public class ServerUtil
    {
        /// <summary>
        /// 检测服务是否存在
        /// </summary>
        /// <returns></returns>
        public static bool Check(string consulIP, string consulPort, string serverName)
        {

            var result = HttpUtil.GetResponse<List<ResServerCheck>>($"http://{consulIP}:{consulPort}/v1/health/checks/{serverName}");

            return result?.Exists(f => f.Status == "passing") ?? false;
        }
    }
}
